import JSONFieldHandler from "../core/JSONFieldHandler"
import JsonSeriable from "../base/JsonSeriable"
import fieldLoader from "../core/fieldLoader"
import FIELD_VALUE_TYPE from "../constants/commonConstants"
import jsonSeriableUtil from "../core/jsonSeriableUtil"
import JsonSeriType from "../base/JsonSeriType"


export default class BaseFieldClass extends JsonSeriable{
	
	#fieldHandler = new JSONFieldHandler(false);
	
	constructor(){
		super();
	}
	/**
	 initOptions  类似结构：
		{
			"fieldGroups":[]
		}
	 其中  fieldGroups 中元素为 FieldGroup 的实例
	 */
	init(initOptions){
		this.#fieldHandler.init(initOptions);
		return this;
	}
	
	genSeriObj(){
		let ret={
			"fieldHandler":this.#fieldHandler
		};
		return ret;
	
	}
	genProdObj(){
		let ret ={
			
		}
		let allFields = this.#fieldHandler.getAllFields(); 
		for(let f of allFields){
			ret[f.code] = f.value || f.defaultValue;
		}
		return ret;
	}
	seriObj(obj){
		this.#fieldHandler =  obj.fieldHandler;
	}
	
	
	getFieldValue(fname){
		return this.#fieldHandler.getFieldValue(fname);
	}
	
	getField(fname){
		return this.#fieldHandler.getField(fname);
	}
	
	setFieldValue(fname,value){
		this.#fieldHandler.setFieldValue(fname, value);
	}
	
	getAllField(){
		return this.#fieldHandler.getAll();
	}
	
	getAllFields(){
		return  this.#fieldHandler.getAllFields();
	}
	
}